Single Message APIs
The following APIs can be used to send templates to end users. Please import the collection from the Single Message API Collection.
Prerequisites
-
WhatsApp Business Account: Share the following details with the Msgkart team so they can send messages on your behalf:
- BusinessId
- PhoneNumberId
- Template
-
Msgkart Account: Once you share the above details, the Msgkart team will create an account for you and provide an API Key.
Request Syntax
POST /api/v1/message/<WHATSAPP BUSINESS ID>/<MESSAGE TYPE>?apikey=<API KEY>
Request Body
{
"message": {
"messageType": "<Message Type>",
"name": "<Template Name>",
"language": "<Language Code>",
"components": []
},
"to": "<Subscriber Id>",
"phoneNumberId": "<Phone Number Id>"
}
Response Body
{
"transactionId": "9bb17cdf-759b-4238-8165-be3191db38dc",
"messageId": "b40b3d68-8514-4792-95f3-a32dbbafb1a6"
}
Properties
Placeholder | Description | Sample |
---|---|---|
messageType | Type of the message being sent. Possible value: template | template |
name | Name of the template created in WhatsApp Business account | payment_template |
language | Language code used to create the template | en_US |
components | List of components like header, body, etc. | |
to | End user phone number | 919999999999 |
phoneNumberId | Phone number ID from WhatsApp Business account |
Components
{
"componentType": "<Component Type>",
"index": "0",
"sub_type": "<url>",
"parameters": []
}
Properties
Placeholder | Description | Sample |
---|---|---|
componentType | Type of component (body , header , button ) | body |
index | Required for button components. Possible values: 0 , 1 , 2 | 0 |
sub_type | Required for buttons. Defines the button action (url ) | url |
parameters | List of parameters that describe the component |
Parameters
{
"type": "<Parameter Type>",
"text": "Any text",
"code": "Currency Code",
"amount": "<amount>",
"date": "<Date>",
"payload": "<button Payload>",
"mediaLink": "<Link to the media object>",
"mediaType": "<media type>",
"fileName": "<File name>"
}
Properties
Parameter | Description | Sample |
---|---|---|
type | Parameter type (currency , text , date_time , payload , media .) | text |
text | Any text to set in the template | MsgKart , Pay now |
code | Currency code (used for currency type) | INR |
amount | Amount to be charged (for currency type) | 1000 |
date | Date to set in the component (for date_time type) | June 6th 2023 |
payload | This field is used only when the component type is button. Its returned when the button is clicked | |
mediaLink | URL of the media object | |
mediaType | Type of media (image , video , document ) | image |
fileName | Name of the document (for media type) | document.pdf |
Examples
Example 1: Template with Header, Body, and Buttons
curl --location 'https://alb-backend.msgkart.com/api/v1/message/<Business Id>/template?apikey=<API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"messageType": "template",
"name": "<Template Name>",
"language": "<Language Code>",
"components": [
{
"componentType": "header",
"parameters": [
{
"type": "media",
"mediaLink": "https://www.msgkart.com/assets/images/pages/logo/color-light.png",
"mediaType": "image"
}
]
},
{
"componentType": "button",
"index": "0",
"sub_type": "url",
"parameters": [
{ "type": "text", "text": "nXdPLQ4cgZ" },
{ "type": "payload", "text": "UUID" }
]
},
{
"componentType": "body",
"parameters": [
{ "type": "date_time", "date": "June 6th 2023" },
{ "type": "currency", "code": "INR", "amount": 1000 },
{ "type": "text", "text": "MsgKart" }
]
}
]
},
"to": "<Subscriber Id>",
"phoneNumberId": "<Phone number Id>"
}'
Example 2: Template with a PDF Document
curl --location 'https://alb-backend.msgkart.com/api/v1/message/<Business ID>/template?apikey=<API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"messageType": "template",
"name": "test_doc_camp",
"language": "en_US",
"components": [
{
"componentType": "header",
"parameters": [
{
"type": "media",
"mediaLink": "https://example.com/file.pdf",
"mediaType": "document",
"fileName": "Test.pdf"
}
]
}
]
},
"to": "919739316704",
"phoneNumberId": "126875363728090"
}'